// JavaScript Document
$(document).ready(function(){
    if('placeholder' in document.createElement("input") === false) {
        $("input").filter("[type=text],[type=password]").placeholder();
    }
});
$.fn.placeholder = function(){
    return this.each(function(){
        var $this = $(this);
        var placeholder = $this.attr("placeholder");

        if(placeholder) {
            $this.wrap('<div class="placeholder_fix"></div>')
                .after('<span class="placeholder"></span>')
                .blur(function(){if($(this).val().length == 0) $(this).next().show();})
                .focus(function(){
                    $(this).next().hide();
                });
            $this.next()
                 .css({
                    lineHeight: $this.parent().height()+"px",
                    fontSize:$this.css("fontSize"),
                    margin:$this.css("margin")
                 }).html(placeholder)
                   .click(function(){
                    // fuck ie7
                    // we can not fire focus of the input during the click event handler
                    // so setTimeout to do it
                    var context = this;
                    setTimeout(function(){$(context).prev().focus();context = null;},50);
                 });
            $this.parent().css({float:$this.css("float")});
            if(this.value) {
                $(this).next().hide();
            }
        }
    });
};